<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<c:set var="reportTitle" value="保养任务报表" />

<%@ include file="/common/report_head.jsp" %>
<%@ include file="/condition/sartTime_YMD_input.html"%>
<%@ include file="/condition/endTime_YMD_input.html"%>
<%@ include file="/condition/fab_sumo.html"%>
<%@ include file="/condition/line_sumo.html"%>
<%@ include file="/condition/toolg_sumo.html"%>
<%@ include file="/condition/toolType_radio.html"%>
<%@ include file="/condition/tool_sumo.html"%>
<%@ include file="/condition/pmType_radio.html"%>
<%@ include file="/condition/shift_sumo.html"%>

<%@ include file="/common/report_middle.jsp" %>
<div class="col-md-12" style="height: 420px;margin-bottom: 25px;">
    <div id="pqGrid"></div>
</div>
<div class="col-md-12" style="height: 420px;margin-bottom: 25px;">
    <div id="pqGrid_detail"></div>
</div>
<%@include file="/common/report_end.jsp" %>

<script>
    $(document).ready(function () {
        $("title").text("保养任务报表");

        $('#query_btn').click(function (){
            initGridAndChart();
            ajax('/jn-report/report/pmTask_report.do' ,loadConditionMapData(), true, ajax_successful);

            function ajax_successful(outTrxObj) {
                if(outTrxObj.gridData.length < 1) { showMessengerDialog("数据查询为空"); return false; }

                // Grid表格动态列
                var colM = [{halign:"center",align:'center', dataIndx: 'fab_id',    title: '厂别',     width: 120,   editable: false, sortable: true},
                    {halign:"center",align:'center', dataIndx: 'fab_id_fk', title: '厂别',     width: 120,   editable: false, sortable: true, hidden: true},
                    {halign:"center",align:'center', dataIndx: 'line_id',   title: '线别',     width: 140,   editable: false, sortable: true},
                    {halign:"center",align:'center', dataIndx: 'line_id_fk',title: '线别',     width: 140,   editable: false, sortable: true, hidden: true},
                    {halign:"center",align:'center', dataIndx: 'tool_id',   title: '设备',     width: 200,   editable: false, sortable: true},
                    {halign:"center",align:'center', dataIndx: 'tool_id_fk',title: '设备',     width: 200,   editable: false, sortable: true, hidden: true},
                    {halign:"center",align:'center', dataIndx: 'pm_type',   title: '保养类型', width: 80,   editable: false, sortable: true},
                    {halign:"center",align:'center', dataIndx: 'pm_type_fk',title: '保养类型', width: 80,   editable: false, sortable: true, hidden: true},
                    {halign:"center",align:'center', dataIndx: 'shift_id',	title: '班别',     width: 50,   editable: false, sortable: true},
                    {halign:"center",align:'center', dataIndx: 'shift_id_fk',	title: '班别', width: 50,   editable: false, sortable: true, hidden: true}];
                for (var i=0; i<outTrxObj.dynamicColumn.length; i++){
                    var day_range = outTrxObj.dynamicColumn[i];
                    colM.push({halign:'center', align:'center',  dataIndx: day_range, title: day_range.substring(5, 10), width: 140, editable: false, sortable: true,
                        render: function (ui) {
                            if (ui.cellData != null && ui.cellData != '' && ui.cellData != 'undefined'){
                                var status = ui.cellData.split("@@@")[0];
                                var keep_time = ui.cellData.split("@@@")[1];
                                var status_color = 'black';
                                if(status === '等待')   status_color = 'red';
                                if(status === '进行中') status_color = 'blue';
                                if(status === '未到期') status_color = 'yellow';
                                if(status === '异常结束') status_color = 'gold';
                                if (status != '等待' && status != '进行中' && status != '未到期' && status != '异常结束') keep_time = "(" + keep_time + ")";
                                //return "<p style='font-size: 13px;color: " + status_color + ";margin: 0;padding: 0;'>" + status + "<i style='color: #8E8E8E;font-size: 11px;'>" + keep_time + "</i></p>";
                                return status + keep_time;
                            }
                        }
                    });
                }
                var formulas = [
                    ["shift_id", function( rd ){
                        var attr = rd.pq_cellattr = rd.pq_cellattr || {};
                        for (var i=0; i<outTrxObj.dynamicColumn.length; i++){
                            var day_range = outTrxObj.dynamicColumn[i];
                            if (rd[day_range] !== undefined && rd[day_range].indexOf('等待') == 0) attr[day_range] = { style: 'font-size: 13px;color: #FF0000;'};
                            if (rd[day_range] !== undefined && rd[day_range].indexOf('进行中') == 0) attr[day_range] = { style: 'font-size: 13px;color: #0000FF;'};
                            if (rd[day_range] !== undefined && rd[day_range].indexOf('未到期') == 0) attr[day_range] = { style: 'font-size: 13px;color: #FFFF00;'};
                            if (rd[day_range] !== undefined && rd[day_range].indexOf('异常结束') == 0) attr[day_range] = { style: 'font-size: 13px;color: #FFD700;'};
                            if (rd[day_range] !== undefined && rd[day_range].indexOf('完成') == 0) attr[day_range] = { style: 'font-size: 11px;'};
                        }
                        return rd.shift_id;
                    }]
                ];
                _pqUtil.f.setColModel($("#pqGrid"), colM);
                _pqUtil.f.setFormulas($("#pqGrid"), formulas);
                _pqUtil.f.seTitle($("#pqGrid"), outTrxObj.gridTitle);
                _pqUtil.f.loadPqGridData($("#pqGrid"), outTrxObj.dynamicColumnJsonGridData);
            };

            // Grid 跳转 Detail Grid数据
            $("#pqGrid").pqGrid({
                rowDblClick: function( event, ui ) {
                    var map = {};
                    if ($("#startTime").length > 0) map['start_time'] = $.trim($("#startTime").val());
                    if ($("#endTime").length > 0) map['end_time'] = $.trim($("#endTime").val());
                    map['fab_id'] = $.trim(ui.rowData.fab_id_fk);
                    map['line_id'] = $.trim(ui.rowData.line_id_fk);
                    map['tool_id'] = $.trim(ui.rowData.tool_id_fk);
                    map['shift_id'] = $.trim(ui.rowData.shift_id_fk);
                    map['pm_type'] = $.trim(ui.rowData.pm_type_fk);
                    map['detail_flag'] = true;

                    ajax('/jn-report/report/pmTask_report.do' ,map, true, detail_ajax_successful);
                    function detail_ajax_successful(outTrxObj) {
                        if(outTrxObj.gridData.length < 1) { showMessengerDialog("数据查询为空"); return false; }
                        /*** Grid表格动态列 **/
                        var colM = [{halign:"center",align:'center', dataIndx: 'item_name',  title: '保养项目', width: 360,   editable: false, sortable: true},
                            {halign:"center",align:'center', dataIndx: 'fab_id',      title: '厂别', width: 120,   editable: false, sortable: true, hidden: true},
                            {halign:"center",align:'center', dataIndx: 'line_id',     title: '线别', width: 140,   editable: false, sortable: true, hidden: true},
                            {halign:"center",align:'center', dataIndx: 'tool_id',     title: '设备', width: 200,   editable: false, sortable: true, hidden: true},
                            {halign:"center",align:'center', dataIndx: 'shift_id',	  title: '班别', width: 50,    editable: false, sortable: true},
                            {halign:"center",align:'center', dataIndx: 'u_spec',	  title: '上限值', width: 60,  editable: false, sortable: true},
                            {halign:"center",align:'center', dataIndx: 'l_spec',	  title: '下限值', width: 60,  editable: false, sortable: true}];
                        for (var i=0; i<outTrxObj.dynamicColumn.length; i++){
                            var date = outTrxObj.dynamicColumn[i];
                            colM.push({halign:'center', align:'center',  dataIndx: date, title: date.substring(5, 10), width: 100, editable: false, sortable: true});
                        }
                        _pqUtil.f.createGrid($("#pqGrid_detail"));
                        _pqUtil.f.setColModel($("#pqGrid_detail"), colM);
                        _pqUtil.f.seTitle($("#pqGrid_detail"), outTrxObj.gridTitle);
                        _pqUtil.f.loadPqGridData($("#pqGrid_detail"), outTrxObj.dynamicColumnJsonGridData);
                        javascript:document.getElementById('pqGrid_detail').scrollIntoView(); //锚点跳转
                    };
                }
            });
        });

    });
</script>
